﻿using AdverseEventReportSystem.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AdverseEventReportSystem.BLL.SchedulingSystem;

namespace AdverseEventReportSystem.BLL
{
    /// <summary>
    /// 休假管理
    /// </summary>
    public class SchedulingPersonnelManager : BaseManager
    {
        /// <summary>
        /// 保存排班人员
        /// </summary>
        /// <param name="leave"></param>
        /// <returns></returns>
        public static OperateResult Save(SchedulingPersonnel[] personnelList)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                SysLoginUser loginUser = LoginManager.GetLoginUser();
                if (personnelList != null)
                {
                    for (int i = 0; i < personnelList.Length; i++)
                    {
                        personnelList[i].DepartmentCode = loginUser.CurrDepCode;
                        personnelList[i].CreateUserID = loginUser.Personnel_id;
                        personnelList[i].CreateTime = DateTime.Now;
                    }
                }
                SchedulingSystemSoapClient service = new SchedulingSystemSoapClient();
                ResultHelperOfBoolean result = service.SaveSchedulingPersonnel(loginUser.CurrDepCode, personnelList);
                if (!result.S)
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }

        /// <summary>
        ///  删除排班人员
        /// </summary>
        /// <param name="departmentCode"></param>
        /// <returns></returns>
        public static OperateResult Del(string departmentCode)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                SchedulingSystemSoapClient service = new SchedulingSystemSoapClient();
                ResultHelperOfBoolean result = service.DelSchedulingPersonnel(departmentCode);
                if (!result.S)
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }
    }
}
